//
//  RegFirstView.m
//  fitnessmanage
//
//  Created by 众拳科技 on 2017/10/17.
//  Copyright © 2017年 zongquankeji. All rights reserved.
//

#import "RegFirstView.h"
//#import "UIButton+Mybutton.h"

@interface RegFirstView()<TTTAttributedLabelDelegate>

@end

@implementation RegFirstView

-(id)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    
    if (self) {
        
        self.backgroundColor = CSWhiteColor;
        /**
         登录Logo
         */
        UIImageView *loginImageView = [[UIImageView alloc] init];
        loginImageView.image = [UIImage imageNamed:@"regLogo"];
        [self addSubview:loginImageView];
        self.loginImageView = loginImageView;
        
        /**
         账号注册
         */
        UIButton *accountRegBtn = [[UIButton alloc] init];
        accountRegBtn.titleLabel.font = BoldBigFont;
        
        accountRegBtn.tag = 0;
        [accountRegBtn setTitle:@"账号注册" forState:UIControlStateNormal];
        [accountRegBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        [accountRegBtn setTitleColor:CSColorFromRGB(0xc7c7cd) forState:UIControlStateNormal];
        [accountRegBtn setTitleColor:CSColorFromRGB(0x0a0a0a) forState:UIControlStateSelected];
        accountRegBtn.selected = YES;
        [self addSubview:accountRegBtn];
        self.accountRegBtn = accountRegBtn;
        
        /**
         分割线
         */
        UIView *horLineView = [[UIView alloc] init];
        horLineView.backgroundColor = CSColorFromRGB(0x212121);
        [self addSubview:horLineView];
        self.horLineView = horLineView;
        
        /**
         手机注册
         */
        UIButton *phoneRegBtn = [[UIButton alloc] init];
        phoneRegBtn.titleLabel.font = BoldBigFont;
        phoneRegBtn.tag = 1;
        [phoneRegBtn setTitle:@"手机注册" forState:UIControlStateNormal];
        [phoneRegBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        [phoneRegBtn setTitleColor:CSColorFromRGB(0xc7c7cd) forState:UIControlStateNormal];
        [phoneRegBtn setTitleColor:CSColorFromRGB(0x0a0a0a) forState:UIControlStateSelected];
        [self addSubview:phoneRegBtn];
        self.phoneRegBtn = phoneRegBtn;
        
        
        /**
         账号注册View
         */
        UIView *accountView = [[UIView alloc] init];
        [self addSubview:accountView];
        self.accountView = accountView;
        
        NSMutableDictionary *attrs = [NSMutableDictionary dictionary];// 创建属性字典
        attrs[NSFontAttributeName] = MidFont; // 设置font
        attrs[NSForegroundColorAttributeName] = PlaceHoldColor; // 设置颜色
        
        
        /**
         手机TF
         */
        UITextField *accountTF = [[UITextField alloc] init];
        //        phoneTF.backgroundColor = CSRedColor;
        accountTF.clearButtonMode=UITextFieldViewModeWhileEditing;
        //accountTF.keyboardType = UIKeyboardTypeNumberPad;
        accountTF.font = MidFont;
        accountTF.textColor = CSColorFromRGB(0x212121);
        NSAttributedString *accountAttStr = [[NSAttributedString alloc] initWithString:@"请输入您的账号" attributes:attrs]; // 初始化富文本占位字符串
        accountTF.attributedPlaceholder = accountAttStr;
        [accountView addSubview:accountTF];
        self.accountTF = accountTF;
        
        accountTF.leftViewMode = UITextFieldViewModeAlways;
        UIButton *userImage = [[UIButton alloc]initWithFrame:CGRectMake(10, 0, 40, 40)];
        
        userImage.userInteractionEnabled = NO;
        
        //        userImage.contentEdgeInsets = UIEdgeInsetsMake(14, 14, 14, 14);
        
        [userImage setImage:[UIImage imageNamed:@"icon_mobilephone"] forState:UIControlStateNormal];
        
        accountTF.leftView = userImage;
        
        UIView *accountLineView = [[UIView alloc] init];
        accountLineView.backgroundColor = LineBackGroundColor;
        [accountView addSubview:accountLineView];
        self.accountLineView = accountLineView;
        
        /**
         密码TF
         */
        UITextField *passWordTF = [[UITextField alloc] init];
        //        passWordTF.backgroundColor = CSRedColor;
        passWordTF.secureTextEntry = YES;
        passWordTF.clearButtonMode=UITextFieldViewModeWhileEditing;
        NSAttributedString *passAttStr = [[NSAttributedString alloc] initWithString:@"请输入密码,至少六位" attributes:attrs]; // 初始化富文本占位字符串
        passWordTF.attributedPlaceholder = passAttStr;
        passWordTF.font = MidFont;
        passWordTF.textColor = CSColorFromRGB(0x212121);
        [accountView addSubview:passWordTF];
        self.passWordTF = passWordTF;
        
        //图标
        passWordTF.leftViewMode = UITextFieldViewModeAlways;
        UIButton *passImage = [[UIButton alloc]initWithFrame:CGRectMake(10, 0, 40, 40)];
        
        passImage.userInteractionEnabled = NO;
        
        //        passImage.contentEdgeInsets = UIEdgeInsetsMake(14, 14, 14, 14);
        
        [passImage setImage:[UIImage imageNamed:@"icon_password"] forState:UIControlStateNormal];
        
        passWordTF.leftView = passImage;
        
        /**
         明文密文显示
         */
        UIButton *lookBtn = [[UIButton alloc] init];
        lookBtn.titleLabel.font = MidFont;
        [lookBtn setImage:[UIImage imageNamed:@"icon_eyes_gary"] forState:UIControlStateNormal];
        [lookBtn setImage:[UIImage imageNamed:@"icon_eyes"] forState:UIControlStateSelected];
        [accountView addSubview:lookBtn];
        self.lookBtn = lookBtn;
        
        UIView *accountLineView1 = [[UIView alloc] init];
        accountLineView1.backgroundColor = LineBackGroundColor;
        [accountView addSubview:accountLineView1];
        self.accountLineView1 = accountLineView1;
        
        
        /**
         手机注册View
         */
        UIView *phoneView = [[UIView alloc] init];
        phoneView.hidden = YES;
        [self addSubview:phoneView];
        self.phoneView = phoneView;


        /**
         +86
         */
        UILabel *phoneFrontLabel = [[UILabel alloc] init];
        phoneFrontLabel.text = @"+86";
        phoneFrontLabel.font = MidBigFont;
        phoneFrontLabel.textColor = CSColorFromRGB(0x0a0a0a);
        [phoneView addSubview:phoneFrontLabel];
        self.phoneFrontLabel = phoneFrontLabel;

        UIImageView *downImageView = [[UIImageView alloc] init];
        downImageView.image = [UIImage imageNamed:@"down"];
        [phoneView addSubview:downImageView];
        self.downImageView = downImageView;
        
        /**
         手机TF
         */
        UITextField *phoneTF = [[UITextField alloc] init];
        //        phoneTF.backgroundColor = CSRedColor;
        phoneTF.clearButtonMode=UITextFieldViewModeWhileEditing;
        phoneTF.keyboardType = UIKeyboardTypeNumberPad;
        phoneTF.font = MidFont;
        NSAttributedString *phoneAttStr = [[NSAttributedString alloc] initWithString:@"请输入您的手机号" attributes:attrs]; // 初始化富文本占位字符串
        phoneTF.attributedPlaceholder = phoneAttStr;
        phoneTF.textColor = CSColorFromRGB(0x212121);
//        UIView *mobileLeftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 15, 15)];
//        phoneTF.leftView = mobileLeftView;
//        phoneTF.leftViewMode = UITextFieldViewModeAlways;
        [phoneView addSubview:phoneTF];
        self.phoneTF = phoneTF;

        UIView *phoneLineView = [[UIView alloc] init];
        phoneLineView.backgroundColor = LineBackGroundColor;
        [phoneView addSubview:phoneLineView];
        self.phoneLineView = phoneLineView;

        /**
         验证码TF
         */
        UITextField *vercodeTF = [[UITextField alloc] init];
        vercodeTF.font = MidFont;
        vercodeTF.textColor = CSColorFromRGB(0x212121);
        NSAttributedString *vercodeAttStr = [[NSAttributedString alloc] initWithString:@"请输入验证码" attributes:attrs]; // 初始化富文本占位字符串
        vercodeTF.attributedPlaceholder = vercodeAttStr;
        vercodeTF.keyboardType = UIKeyboardTypeNumberPad;
        [phoneView addSubview:vercodeTF];
        self.vercodeTF = vercodeTF;

        /**
         发送验证码
         */
        UIButton *sendVercodeBtn = [[UIButton alloc] init];
        [sendVercodeBtn setTitle:@"获取验证码" forState:UIControlStateNormal];
        sendVercodeBtn.titleLabel.font = MidBigFont;
        [sendVercodeBtn setTitleColor:CSColorFromRGB(0x0a0a0a) forState:UIControlStateNormal];
        [sendVercodeBtn setTitleColor:PlaceHoldColor forState:UIControlStateDisabled];
        [phoneView addSubview:sendVercodeBtn];
        self.sendVercodeBtn = sendVercodeBtn;

        UIView *phoneineView1 = [[UIView alloc] init];
        phoneineView1.backgroundColor = LineBackGroundColor;
        [phoneView addSubview:phoneineView1];
        self.phoneineView1 = phoneineView1;
        
        /**
         下一步按钮
         */
        UIButton *nextBtn = [[UIButton alloc] init];
        nextBtn.backgroundColor = ButtonBackGroundColor;
        nextBtn.layer.cornerRadius = 4;
        nextBtn.layer.masksToBounds = YES;
        [nextBtn setTitle:@"下一步" forState:UIControlStateNormal];
        [nextBtn setTitleColor:CSBlackColor forState:UIControlStateNormal];
        nextBtn.titleLabel.font = BigFont;
        [self addSubview:nextBtn];
        self.nextBtn = nextBtn;
        
        /**
         第三方注册
         */
//        ThirdLoginView *thirdLoginView  = [[ThirdLoginView alloc] init];
//        thirdLoginView.titleLabel.text = @"第三方快速注册";
//        thirdLoginView.titleLabel.textColor = TextColor1;
//        [self addSubview:thirdLoginView];
//        self.thirdLoginView = thirdLoginView;
//
//        [thirdLoginView.weChatButton setBackgroundImage:[UIImage imageNamed:@"register_wx"] forState:UIControlStateNormal];
//
//        [thirdLoginView.qqButton setBackgroundImage:[UIImage imageNamed:@"register_qq"] forState:UIControlStateNormal];
//
//        [thirdLoginView.sinaButton setBackgroundImage:[UIImage imageNamed:@"register_wb"] forState:UIControlStateNormal];
        
        [self setConstraints];
    }
    
    return self;
}

-(void)setConstraints{
    
    /**
     登录Logo
     */
    [self.loginImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
//        make.bottom.mas_equalTo(self.mas_centerY).offset(-80);
        
        make.top.mas_equalTo(self).offset(30);
        
        make.centerX.mas_equalTo(self);
    }];
    
    /**
     账号注册
     */
    [self.accountRegBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.loginImageView.mas_bottom).offset(30);
        
        make.left.mas_equalTo(self).offset(25);
    }];
    
    /**
     分割线
     */
    [self.horLineView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.left.width.mas_equalTo(self.accountRegBtn);
        
        make.height.mas_equalTo(3);
        
        make.top.mas_equalTo(self.accountRegBtn.mas_bottom).offset(5);
    }];
    
    /**
     手机注册
     */
    [self.phoneRegBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.width.height.mas_equalTo(self.accountRegBtn);
        
        make.left.mas_equalTo(self.accountRegBtn.mas_right).offset(20);
    }];
    
    /**
     账号注册View
     */
    [self.accountView mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.top.mas_equalTo(self.accountRegBtn.mas_bottom).offset(20);
        
        make.left.width.mas_equalTo(self);
    }];
    
    /**
     手机TF
     */
    [self.accountTF mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.accountView).offset(5);
        
        make.left.mas_equalTo(self.accountView).offset(25);
        
        make.right.mas_equalTo(self.accountView).offset(-25);
        
        make.height.mas_equalTo(40);
    }];
    
    [self.accountLineView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.left.width.mas_equalTo(self.accountTF);
        
        make.height.mas_equalTo(1);
        
        make.top.mas_equalTo(self.accountTF.mas_bottom).offset(10);
    }];
    
    /**
     密码TF
     */
    [self.passWordTF mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.accountLineView.mas_bottom).offset(15);
        
        make.left.width.height.mas_equalTo(self.accountTF);
        
    }];
    
    /**
     明文密文显示
     */
    [self.lookBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_equalTo(self).offset(-15);
        
        make.centerY.mas_equalTo(self.passWordTF);
    }];
    
    [self.accountLineView1 mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.left.width.mas_equalTo(self.passWordTF);
        
        make.height.mas_equalTo(1);
        
        make.top.mas_equalTo(self.passWordTF.mas_bottom).offset(10);
        
        make.bottom.mas_equalTo(self.accountView).offset(-10);
    }];
    
    /**
     手机注册View
     */
    [self.phoneView mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.top.mas_equalTo(self.accountRegBtn.mas_bottom).offset(20);
        
        make.left.width.mas_equalTo(self);
    }];
    
    /**
     +86
     */
    [self.phoneFrontLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(self.phoneView).offset(25);
        
        make.centerY.mas_equalTo(self.phoneTF);
        
        make.width.mas_equalTo(35);
    }];
    
    [self.downImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.centerY.mas_equalTo(self.phoneFrontLabel);
        
        make.left.mas_equalTo(self.phoneFrontLabel.mas_right);
        
        make.width.height.mas_equalTo(5);
    }];
    
    /**
     手机TF
     */
    [self.phoneTF mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.phoneView).offset(5);
        
        make.left.mas_equalTo(self.downImageView.mas_right).offset(20);
        
        make.right.mas_equalTo(self.phoneView).offset(-25);
        
        make.height.mas_equalTo(40);
    }];
    
    [self.phoneLineView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(self.phoneFrontLabel);
        
        make.right.mas_equalTo(self.phoneView).offset(-25);
        
        make.height.mas_equalTo(1);
        
        make.top.mas_equalTo(self.phoneTF.mas_bottom).offset(10);
    }];
    
    /**
     验证码TF
     */
    [self.vercodeTF mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.phoneLineView.mas_bottom).offset(15);
        
        make.left.mas_equalTo(self.phoneView).offset(25);
        
        make.right.mas_equalTo(self.phoneView).offset(-25);
        
        make.height.mas_equalTo(self.phoneTF);
    }];
    
    /**
     发送验证码
     */
    [self.sendVercodeBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_equalTo(self).offset(-15);
        
        make.width.mas_equalTo(120);
        
        make.height.mas_equalTo(30);
        
        make.centerY.mas_equalTo(self.vercodeTF);
    }];
    
    [self.phoneineView1 mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.left.width.mas_equalTo(self.vercodeTF);
        
        make.height.mas_equalTo(1);
        
        make.top.mas_equalTo(self.vercodeTF.mas_bottom).offset(10);
        
        make.bottom.mas_equalTo(self.phoneView).offset(-10);
    }];
    
    //下一步
    [self.nextBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.accountView.mas_bottom).offset(35);
        
        make.left.mas_equalTo(self).offset(30);
        
        make.right.mas_equalTo(self).offset(-30);
        
        make.height.mas_equalTo(50);
    }];
    
    /**
     第三方注册
     */
//    [self.thirdLoginView mas_remakeConstraints:^(MASConstraintMaker *make) {
//        
//        
//        
//        make.left.width.mas_equalTo(self);
//        
////        make.bottom.mas_equalTo(self).offset(-20);
//        
//        
//        make.top.mas_equalTo(self.nextBtn.mas_bottom).offset(60);
//    }];
}


#pragma mark BtnClick

-(void)btnClick:(UIButton *)btn{
    
    //账号注册
    if (btn.tag == 0) {
        
        self.accountRegBtn.selected = YES;
        
        self.phoneRegBtn.selected = NO;
        
        self.accountView.hidden = NO;
        
        self.phoneView.hidden = YES;
        
        [UIView animateWithDuration:0.25 animations:^{
            
            CGRect frame = self.horLineView.frame;
            
            frame.origin.x = self.accountRegBtn.frame.origin.x;
            
            self.horLineView.frame = frame;
        }];
        
        //下一步
        [self.nextBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
            
            make.top.mas_equalTo(self.accountView.mas_bottom).offset(35);
            
            make.left.mas_equalTo(self).offset(30);
            
            make.right.mas_equalTo(self).offset(-30);
            
            make.height.mas_equalTo(50);
        }];
    }
    else{
        
        self.accountRegBtn.selected = NO;
        
        self.phoneRegBtn.selected = YES;
        
        self.accountView.hidden = YES;
        
        self.phoneView.hidden = NO;
        
        [UIView animateWithDuration:0.25 animations:^{
            
            CGRect frame = self.horLineView.frame;
            
            frame.origin.x = self.phoneRegBtn.frame.origin.x;
            
            self.horLineView.frame = frame;
        }];
        
        //下一步
        [self.nextBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
            
            make.top.mas_equalTo(self.phoneView.mas_bottom).offset(35);
            
            make.left.mas_equalTo(self).offset(30);
            
            make.right.mas_equalTo(self).offset(-30);
            
            make.height.mas_equalTo(50);
        }];
    }
    
    
}

@end
